/***************************************************************************
 *   Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN  *
 *   {prenom.nom}_at_lip6.fr                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/** @file
 * @brief Common tools used by learning algorithms
 *
 * @author Maroua HAMMAMI and Malak HAMZEH
 *
 * This file provides common tools used by various learning algorithms.
 * */
#ifndef DOXYGEN_SHOULD_SKIP_THIS

namespace gum {
	INLINE CountTree::CountTree(const Database &database):__database(database),__root(0),__leaves(),__variables(database.nbrModalities()),__levels(0)
	{
			 GUM_CONSTRUCTOR(CountTree);
	}
	//a voir  le contenu de __variables
	INLINE void CountTree::clear()
	{
		__root=0;
		__leaves.clear();
		__levels.clear();
	}

	INLINE void CountTree::eraseLastParent()
	{
		for(unsigned int i=0;i<__levels.size();++i)	
		{
				delete(&__levels[i]);
		}
	}


	INLINE List<const InstantiationBox *>& CountTree::count()
	{
		return __leaves;
	}

	INLINE void CountTree::setVariables(vector<unsigned int> variables)
	{
		__variables=variables;
	}

	INLINE 	unsigned int CountTree::findParent(unsigned int parent)
	{
		unsigned int i=0;
		while(parent!=__variables[i] && i<__variables.size())
			++i;
		return i;
	}

	INLINE	void CountTree::eraseParent(unsigned int position)
	{
		for(unsigned int i=position;i<__levels.size();++i)
			delete(__levels[i]);
	}
}//end gum
#endif  // DOXYGEN_SHOULD_SKIP_THIS
